from forward.api.h5.orm.contact import ContactORM
from forward.model.schemas.contact import ContactAddInSchema, ContactSchema


class ContactService:
    def __init__(self) -> None:
        pass

    async def add(self, add_in: ContactAddInSchema) -> ContactSchema | None:
        one = await ContactORM.get_one_by_params(user_id=add_in.user_id)
        if not one:
            id = await ContactORM.insert(add_in)
            if id:
                one = await ContactORM.get_one_by_id(id)
        return one
